import { _decorator, Component, Node, Vec3, v2, Quat } from "cc";
const { ccclass, property } = _decorator;

@ccclass("Direct")
export class Direct extends Component {
    @property(Node)
    private mid: Node = null;

    @property(Node)
    private top: Node = null;

    @property(Node)
    private ball: Node = null;

    private ratio: number = 0.5;
    /* class member could be defined like this */
    // dummy = '';

    /* use `property` decorator if your want the member to be serializable */
    // @property
    // serializableDummy = 0;

    onLoad():void{
        this.setLen(0.2);
    }

    start () {
        // Your initialization goes here.
    }

    // update (deltaTime: number) {
    //     // Your update function goes here.
    // }

    setLen(len: number): void{
        len = this.ratio * len;        
        let v3: Vec3 = cc.v3();

        v3 = this.mid.getScale();
        v3.y = len;
        this.mid.setScale(v3);

        v3 = this.mid.position;
        cc.log(v3);
        v3.z = - len / 2;
        cc.log(v3);
        this.mid.setPosition(v3);

        v3 = this.top.position;
        v3.z = -len;
        this.top.setPosition(v3);
    }

    setDirect(angle: number): void{
        let quat: Quat = new Quat();
        quat = this.node.getRotation();
        quat.y = angle;
        this.node.setRotation(quat);

    }
}
